<?php include 'header.php'; ?>
<h1>Search Results</h1>

<script type='text/template' id='roomtemplate'>
    {{#each objects}}
        {{#if roomtype_info}}
    
    
    <div class="well">
    <table width="100%" cellpadding="10"><tr><td><h1>{{hotel_info.hotelName}}</h1></td><td><p>{{hotel_info.streetAddress}}<br>{{hotel_info.city}}, {{hotel_info.stateOrProvince}} {{hotel_info.postalCode}}</p></td><td><p><a href="{{../hotel_info/hotelURL}}" class="btn btn-primary btn-large">Visit Hotel Web Site &raquo;</a></p></td></tr></table>
    <table cellpadding="10"><tr><td>
    <img align="left" src="img/hotel_{{hotel_info.hotelId}}.jpg"></td><td valign="top"><table cellpadding="5" class="table" width="100%"><tr><th><b>Room Type</b></th><th><b>Daily Rate</b></th><th><b></b></th></tr>
                    {{#each roomtype_info}}
                    <tr><td>{{roomTypeDescription}}</td><td><b>${{roomRate}}</b></td><td><b><a href="reservationconfirm.php?hotelName={{../hotel_info/hotelName}}&roomTypeCode={{roomTypeCode}}&hotelId={{../hotel_info/hotelId}}&roomTypeDescription={{roomTypeDescription}}&smokingYN={{smokingYN}}&roomRate={{roomRate}}&indate=<?php echo($_GET["indate"]); ?>&outdate=<?php echo($_GET["outdate"]); ?>" class="btn btn-primary btn-medium">Reserve This Room &raquo;</a></b></td></tr>

{{/each}}
</table>
    </td></tr>
    </table>
    </div>
    
    {{/if}}    
    
    
            {{/each}}
</script>


<script type="text/javascript">
    function loadRooms() {
        $("#content").html("Loading ...");

        var xmlhttp;
        if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari
            xmlhttp = new XMLHttpRequest();
        }
        else {// code for IE6, IE5
            xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
        }
        xmlhttp.onreadystatechange = function() {
            if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
                var data = JSON.parse(xmlhttp.responseText);
                //data.pop();
                var source = $("#roomtemplate").html();
                var template = Handlebars.compile(source);
                $("#content").html(template({objects: data}));

                if (data.length == 0)
                    $("#content").html("No rooms matching selected criteria");
            }
        }//xmlhttp.onreadystatechange
        xmlhttp.open("GET", "db/RoomAvailabilitySearch.php?bedtype=" + $("#bedtype").val() + "&dest=" + $("#destination").val() + "&smoking=" + $("#smoking").val() + "&indate=" + $("#dpd1").val() + "&outdate=" + $("#dpd2").val()+ "&maxprice=" + $("#maxprice").val()+ "&minprice=" + $("#minprice").val(), true);
        xmlhttp.send();
    } //end function loadLocations()
</script>

<div class="well">Bed type: <select onChange="loadRooms()" class="span2" id="bedtype">
        <option value="">No Selection</option> 
        <option value="king">King Size Bed</option>
        <option value="queen">Queen Size Bed</option>
        <option value="twin">Twin Beds</option>
    </select>

    Smoking: <select onChange="loadRooms()" class="span2" id="smoking">
        <option value="">No Selection</option> 
        <option value="yes">Smoking</option>
        <option value="no">Non Smoking</option>
    </select>


    Maximum Price: <select onChange="loadRooms();" class="span2" id="maxprice">
        <option value="">No Selection</option> 
        <option value="0">$0</option>
        <option value="25">$25</option>
        <option value="50">$50</option>
        <option value="75">$75</option>
        <option value="100">$100</option>
        <option value="125">$125</option>
        <option value="150">$150</option>
        <option value="175">$175</option>
        <option value="200">$200</option>
        <option value="225">$225</option>
        <option value="250">$250</option>
        <option value="275">$275</option>
        <option value="300">$300</option>
        <option value="325">$325</option>
    </select>

    Minimum Price: <select onChange="loadRooms();" class="span2" id="minprice">
        <option value="">No Selection</option> 
        <option value="0">$0</option>
        <option value="25">$25</option>
        <option value="50">$50</option>
        <option value="75">$75</option>
        <option value="100">$100</option>
        <option value="125">$125</option>
        <option value="150">$150</option>
        <option value="175">$175</option>
        <option value="200">$200</option>
        <option value="225">$225</option>
        <option value="250">$250</option>
        <option value="275">$275</option>
        <option value="300">$300</option>
        <option value="325">$325</option>
    </select>

  <br>Destination: <input onchange="loadRooms();" type="text" class="span2" value="<?php echo($_GET['destination']); ?>" name="destination" id="destination" >
Check in: <input onChange="loadRooms();" type="text" class="span2" value="<?php echo($_GET['indate']); ?>" name="indate" id="dpd1" >
    Check out: <input onChange="loadRooms();" type="text" class="span2" value="<?php echo($_GET['outdate']); ?>" name="outdate" id="dpd2" >
</div>

<div id="content">
    Loading ...
</div>
<script>
    $(document).ready(function() {
        $(function() {
            loadRooms();
        });
    });
</script>
<?php include 'footer.php'; ?>